package com.chenchen.tiguan.equipment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenchen.tiguan.common.annotation.Log;
import com.chenchen.tiguan.common.core.controller.BaseController;
import com.chenchen.tiguan.common.core.domain.AjaxResult;
import com.chenchen.tiguan.common.enums.BusinessType;
import com.chenchen.tiguan.equipment.domain.EquipmentReservation;
import com.chenchen.tiguan.equipment.service.IEquipmentReservationService;
import com.chenchen.tiguan.common.utils.poi.ExcelUtil;
import com.chenchen.tiguan.common.core.page.TableDataInfo;

/**
 * 设备预约管理Controller
 * 
 * @author chenchen
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/equipment/reservation")
public class EquipmentReservationController extends BaseController
{
    @Autowired
    private IEquipmentReservationService equipmentReservationService;

    /**
     * 查询设备预约管理列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:reservation:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentReservation equipmentReservation)
    {
        startPage();
        List<EquipmentReservation> list = equipmentReservationService.selectEquipmentReservationList(equipmentReservation);
        return getDataTable(list);
    }

    /**
     * 导出设备预约管理列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:reservation:export')")
    @Log(title = "设备预约管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentReservation equipmentReservation)
    {
        List<EquipmentReservation> list = equipmentReservationService.selectEquipmentReservationList(equipmentReservation);
        ExcelUtil<EquipmentReservation> util = new ExcelUtil<EquipmentReservation>(EquipmentReservation.class);
        util.exportExcel(response, list, "设备预约管理数据");
    }

    /**
     * 获取设备预约管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:reservation:query')")
    @GetMapping(value = "/{reservationId}")
    public AjaxResult getInfo(@PathVariable("reservationId") Long reservationId)
    {
        return success(equipmentReservationService.selectEquipmentReservationByReservationId(reservationId));
    }

    /**
     * 新增设备预约管理
     */
    @PreAuthorize("@ss.hasPermi('equipment:reservation:add')")
    @Log(title = "设备预约管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentReservation equipmentReservation)
    {
        return toAjax(equipmentReservationService.insertEquipmentReservation(equipmentReservation));
    }

    /**
     * 修改设备预约管理
     */
    @PreAuthorize("@ss.hasPermi('equipment:reservation:edit')")
    @Log(title = "设备预约管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentReservation equipmentReservation)
    {
        return toAjax(equipmentReservationService.updateEquipmentReservation(equipmentReservation));
    }

    /**
     * 删除设备预约管理
     */
    @PreAuthorize("@ss.hasPermi('equipment:reservation:remove')")
    @Log(title = "设备预约管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reservationIds}")
    public AjaxResult remove(@PathVariable Long[] reservationIds)
    {
        return toAjax(equipmentReservationService.deleteEquipmentReservationByReservationIds(reservationIds));
    }
}
